package com.ruoyi.equipment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.equipment.domain.LgEquipmentError;
import com.ruoyi.equipment.domain.LgMachine;
import com.ruoyi.equipment.mapper.LgEquipmentErrorMapper;
import com.ruoyi.equipment.service.LgEquipmentErrorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * @Author: lek
 * @Description: TODO
 * @Date: 2025/3/10 14:42
 * @Version: 1.0
 */
@Service
public class LgEquipmentErrorServiceImpl implements LgEquipmentErrorService {
    @Autowired
    private LgEquipmentErrorMapper lgEquipmentErrorMapper;
    @Override
    public List<LgEquipmentError> selectLgEquipmentErrorList(LgEquipmentError lgEquipmentError) {
        QueryWrapper<LgEquipmentError> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(lgEquipmentError.getDeviceNumber() != null,"device_number",lgEquipmentError.getDeviceNumber())
        .eq(lgEquipmentError.getEquipmentType() != null,"equipment_type",lgEquipmentError.getEquipmentType())
        .between(lgEquipmentError.getParams().get("beginTime") != null,"alarm_time",lgEquipmentError.getParams().get("beginTime"),lgEquipmentError.getParams().get("endTime"));
        return lgEquipmentErrorMapper.selectList(queryWrapper);
    }

    @Override
    public int insertLgEquipmentError(LgEquipmentError lgEquipmentError) {
        return lgEquipmentErrorMapper.insert(lgEquipmentError);
    }

    @Override
    public int updateLgEquipmentError(LgEquipmentError lgEquipmentError) {
        return lgEquipmentErrorMapper.updateById(lgEquipmentError);
    }

    @Override
    public int deleteLgEquipmentErrorById(Integer id) {
        return lgEquipmentErrorMapper.deleteById(id);
    }

    @Override
    public int deleteLgEquipmentErrorByIds(Integer[] id) {
        for (int i = 0; i < id.length; i++){
            LgEquipmentError lgMachine = lgEquipmentErrorMapper.selectById(id[i]);
            lgMachine.setId(id[i]);
            //删除时解车辆
            lgEquipmentErrorMapper.updateById(lgMachine);
        }
        return lgEquipmentErrorMapper.deleteBatchIds(Arrays.asList(id));
    }

    @Override
    public LgEquipmentError selectLgEquipmentErrorById(Integer id) {
        return lgEquipmentErrorMapper.selectById(id);
    }
}
